-- 威临技能
local LuaWeiling = fk.CreateSkill{
  name = "LuaWeiling",
  tags = {Skill.Limited},
}

Fk:loadTranslationTable{
  ["LuaWeiling"] = "威临",
  ["#LuaWeiling-damage"] = "威临：你可以令这张雷杀伤害+1，然后清除你所有已有标记",
  ["#LuaWeiling"] = "威临：你可以连续使用9张「雷杀」",
  ["#LuaWeilingTTT"] = "威临：你可以连续使用9张「雷杀」（第%arg张，共9张）",
  [":LuaWeiling"] = "限定技，出牌阶段，你视为对一名其他角色使用9张「雷杀」，每当你因此法造成伤害前，你可以令这张「雷杀」伤害+1，然后清除你的武将牌上所有标记。",
}

LuaWeiling:addEffect("active", {
    card_num = 0,
    target_num = 0,
    prompt = "#LuaWeiling",
    can_use = function(self, player)
        return player:usedSkillTimes(LuaWeiling.name, Player.HistoryGame) == 0
    end,
    card_filter = Util.FalseFunc,
    on_use = function(self, room, effect)
        local player = effect.from
        for i = 1, 9 do
            if player.dead or not room:askToUseVirtualCard(player, {
                name = "thunder__slash",
                skill_name = LuaWeiling.name,
                prompt = "#LuaWeilingTTT:::" .. i,
                cancelable = true,
                extra_data = {
                    bypass_times = true,
                    extraUse = true,
                },
            }) then
                break
            end
        end

    end,
})

-- 处理雷杀伤害
LuaWeiling:addEffect(fk.PreDamage, {
    is_delay_effect = true,
    mute = true,
  can_trigger = function(self, event, target, player, data)
    local num = 0
    local marks = player:getMarkNames()
      for _, m in ipairs(marks) do
        local mark = player:getMark(m)
        if m:startsWith("") then
          if type(mark) == "table" then
            num = num + #mark
          elseif type(mark) == "number" then
            num = num + mark
          end
        end
      end
      if num > 0 then
        return target == player and data.card and data.card.name == "thunder__slash" and data.card.skillName == LuaWeiling.name
      end
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askToSkillInvoke(player, {
      skill_name = LuaWeiling.name,
      prompt = "#LuaWeiling-damage"
    })
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local mark = player:getMarkNames()
    if #mark > 0 then
      for _, v in ipairs(mark) do
        if v:startsWith("") then
          room:setPlayerMark(player,v,0)
        end
      end
    end
    data.damage = data.damage + 1
    
  end,
})

  return LuaWeiling